1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.google.common.cache;
16
17 import com.google.common.annotations.GwtCompatible;
18
19 import java.util.concurrent.atomic.AtomicInteger;
20
21
22
23
24
25
26 @GwtCompatible(emulated = true)
27 class TestingRemovalListeners {
28
29
30
31
32 static <K, V> NullRemovalListener<K, V> nullRemovalListener() {
33 return new NullRemovalListener<K, V>();
34 }
35
36
37
38
39 static <K, V> CountingRemovalListener<K, V> countingRemovalListener() {
40 return new CountingRemovalListener<K,V>();
41 }
42
43
44
45
46
47 static class CountingRemovalListener<K, V> implements RemovalListener<K, V> {
48 private final AtomicInteger count = new AtomicInteger();
49 private volatile RemovalNotification<K, V> lastNotification;
50
51 @Override
52 public void onRemoval(RemovalNotification<K, V> notification) {
53 count.incrementAndGet();
54 lastNotification = notification;
55 }
56
57 public int getCount() {
58 return count.get();
59 }
60
61 public K getLastEvictedKey() {
62 return lastNotification.getKey();
63 }
64
65 public V getLastEvictedValue() {
66 return lastNotification.getValue();
67 }
68
69 public RemovalNotification<K, V> getLastNotification() {
70 return lastNotification;
71 }
72 }
73
74
75
76
77 static class NullRemovalListener<K, V> implements RemovalListener<K, V> {
78 @Override
79 public void onRemoval(RemovalNotification<K, V> notification) {}
80 }
81 }
82